package com.tools.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;

/**
 * 容器启动完成监听
 */
@Slf4j
public class ApplicationStartedListener implements ApplicationListener<ApplicationReadyEvent>
{

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent)
    {
        // 先获取到application上下文
        ApplicationContext applicationContext = applicationReadyEvent.getApplicationContext();

        // 获取对应的service
//        RedisService redisService = applicationContext.getBean(RedisService.class);

        // 获取application域对象，将查到的信息放到application域
        // ServletContext application = applicationContext.getBean(ServletContext.class);
        // application.setAttribute("redisService", redisService);

//        redisService.loadData();

//        log.info("容器初始化完成{}",redisService);
    }
}
